package com.rms.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.rms.domain.CompanyManager;
import com.rms.domain.Job;
import com.rms.domain.ResumeJob;

/**
 * Servlet implementation class ToSendResumeToHRPageServlet
 */
@WebServlet("/ToSendResumeToHRPageServlet")
public class ToSendResumeToHRPageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
   

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//getJobs是公司发布的所有工作
		//得到jobList
		List<Job> jobList = ((CompanyManager)(request.getSession().getAttribute("companyManager"))).getCompany().getJobs();
		//保存未分配hr的简历
		List<ResumeJob> resultList = new ArrayList<>();
		//保存job中取出的List<ResumeJob>
		List<ResumeJob> tempList;
		//双重循环得到未分配hr的list
		for(int i=0;i<jobList.size();i++) {
			tempList = jobList.get(i).getResumeJobs();
			for(ResumeJob r : tempList) {
				if(r.getHr()==null) {
					//若未分配HR，加入resultList
					resultList.add(r);
				}
			}
		}
		//需要的是投简历还在审核过程中的简历->resumeJob
		request.setAttribute("resumeJobList", resultList);
		//得到hr_id，通过request保存数据只在一次请求期间有效，，如果不设置hr_id，跳转到下个界面会失效
		String hr_id = request.getParameter("hr_id");
		request.setAttribute("hr_id", hr_id);
//		System.out.println("hr="+hr_id);
		request.getRequestDispatcher("sendResumeToHR.jsp").forward(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
